
import { Path, Vector2, Vector3 } from "three";
import AModelFmulaUtils from "./AModelFmulaUtils";
import IronUtils from "./IronUtils";
import MoldUtils from "./MoldUtils";
import VectorUtils from "./VectorUtils";
import { AK } from "../const/ModelConst";

export default class DorsalRidgeUtils {

    static getIronPath(s1: Vector3, e1: Vector3, w: number, len: number, ag: number, normal: Vector3, one: boolean, two: boolean) {

        let se1 = e1.clone().sub(s1);

        let se1nor = se1.clone().applyAxisAngle(normal, -Math.PI / 2);

        let l1 = s1.distanceTo(e1);
        let l2 = len;
        let arc2 = ag * Math.PI / 180;

        let se2 = se1.clone().applyAxisAngle(normal, arc2);

        let dir2 = se2.clone().setLength(l2);

        let se2nor = se1nor.clone().applyAxisAngle(normal, arc2);

        let s2 = e1.clone();
        let e2 = e1.clone().add(dir2);

        se1nor.setLength(w);
        se2nor.setLength(w);

        let s1p = s1.clone().add(se1nor);

        let e1p = e1.clone().add(se1nor);

        let s2p = s2.clone().add(se2nor);

        let e2p = e2.clone().add(se2nor);

        let isec = VectorUtils.segmentsIntr(
            new Vector2(s1.x, s1.z),
            new Vector2(e1.x, e1.z),
            new Vector2(s2.x, s2.z),
            new Vector2(e2.x, e2.z)
        );

        let isecp = VectorUtils.segmentsIntr(
            new Vector2(s1p.x, s1p.z),
            new Vector2(e1p.x, e1p.z),
            new Vector2(s2p.x, s2p.z),
            new Vector2(e2p.x, e2p.z)
        );

        let checkDis: number = 0;
        let dvalue: number = 0;
        let checkdir: Vector3;
        let changeA: Vector3;
        let changeB: Vector3;
        let changeC: Vector3;
        let changeD: Vector3;
        let changeE: Vector3;
        let changeF: Vector3;

        let ls: Vector3;
        let le: Vector3;

        let isOne = Math.abs(Math.abs(ag) - 90) < 0.1 && one;
        let isTwo = Math.abs(Math.abs(ag) - 90) < 0.1 && two;

        let path1 = [];
        let path2 = [];
        if (isOne) {

            if (ag < 0) {
                path1 = [s1, s1p, e1p, e1, s1];

                checkDis = isecp.distanceTo(e2p);
                dvalue = checkDis - l2;

                checkdir = isecp.clone().sub(e2p).setLength(dvalue);
                changeA = e2p.clone().add(checkdir);
                changeB = e2.add(checkdir);


                ls = e1p.clone();
                le = changeB.clone();

                path2 = [e1p, isecp, changeA, changeB, e1p];
            }
            else {

                path1 = [s1, s1p, e1p, e1, s1];

                checkdir = s1.clone().sub(e1).setLength(w);

                changeC = s2.clone().add(checkdir);
                changeD = s2p.clone().add(checkdir);
                changeE = e2p.clone().add(checkdir);
                changeF = e2.add(checkdir);


                ls = changeC.clone();
                le = changeF.clone();

                path2 = [changeC, changeD, changeE, changeF, changeC];

            }

        }
        else if (isTwo) {
            if (ag < 0) {
                checkDis = isecp.distanceTo(s1p);
                dvalue = checkDis - l1;

                checkdir = s1p.clone().sub(e1p).setLength(dvalue);

                changeC = s2.clone().add(checkdir);
                changeD = s2p.clone().add(checkdir);
                changeE = e2p.clone().add(checkdir);
                changeF = e2.add(checkdir);


                path1 = [s1, s1p, e1p, e1, s1];

                ls = changeC.clone();
                le = changeF.clone();

                path2 = [changeC, changeD, changeE, changeF, changeC];


            }
            else {
                path1 = [s1, s1p, e1p, e1, s1];

                checkDis = isecp.distanceTo(e2p);
                dvalue = checkDis - l2;

                checkdir = isecp.clone().sub(e2p).setLength(dvalue);
                changeA = e2p.clone().add(checkdir);
                changeB = e2.clone().add(checkdir);


                ls = e1p.clone();
                le = changeB.clone();

                path2 = [e1p, isecp, changeA, changeB, s2];
            }
        }
        else {

            path1 = [s1, s1p, isecp, isec, s1];

            path2 = [isec, isecp, e2p, e2, isec];

            ls = e1.clone();
            le = e2.clone();
        }

        return [path1, path2, ls, le, se1nor, se2nor];
    }

    static getLenagData(lenag: string): number[][] {
        let lenagAry = lenag.split(')');
        let laAry: string[];
        let lenangle: string[];
        let result: number[][] = [];
        for (let i = 0; i < lenagAry.length; i++) {

            laAry = lenagAry[i].split('(');
            if (laAry.length === 2) {
                lenangle = laAry[1].split(',');

                if (i > 0 && ((Number(lenangle[1]) > -0.1 && Number(lenangle[1]) < 0.1) ||
                    Number(lenangle[1]) < - 179.9 ||
                    Number(lenangle[1]) > 179.9 ||
                    Number(lenangle[0]) < 1)) {
                    continue;
                }
                result.push([Number(lenangle[0]), Number(lenangle[1]), Number(lenangle[2])]);
            }
        }
        return result;
    }

    static getDorsalridgePath(s1: Vector3, e1: Vector3, result: number[][], W: number, isV: boolean): any[] {

        // 解构
        let paths: any[] = [];
        let tmp: any[];

        // let dir = e1.clone().sub(s1);
        // let up = new Vector3(0, 1, 0);
        let normal = new Vector3(0, 1, 0)
        // if(isV){
        //     normal = dir.clone().cross(up).normalize();
        // }

        if (result.length === 1) {
            let se1 = e1.clone().sub(s1);

            // let normal = new Vector3(0, 1, 0);

            let se1nor = se1.clone().applyAxisAngle(normal, -Math.PI / 2);
            se1nor.setLength(W);

            let s1p = s1.clone().add(se1nor);

            let e1p = e1.clone().add(se1nor);

            return [[[s1, s1p, e1p, e1], se1nor]];
        }



        // 头
        tmp = DorsalRidgeUtils.getIronPath(s1, e1, W, result[1][0], result[1][1], normal, false, true);
        paths.push([tmp[0], tmp[4]])

        let sr = tmp[1];

        for (let i = 2; i < result.length; i++) {

            let one = i % 2 === 0;
            let two = (i + 1) % 2 === 0;

            tmp = DorsalRidgeUtils.getIronPath(tmp[2], tmp[3], W, result[i][0], result[i][1], normal, one, two);

            tmp[0][0] = sr[0];
            tmp[0][1] = sr[1];

            tmp[0][4] = sr[4];

            paths.push([tmp[0], tmp[4]]);

            sr = tmp[1];
        }
        // 尾
        paths.push([tmp[1], tmp[5]]);

        return paths;
    }


    static getHolePathVI(count: number, vertices: number[], indices: number[], facevec: Vector3[][],
        blh: number, tphd: number, a: Vector3, b: Vector3, c: Vector3, d: Vector3, ydir: Vector3): number {
        let abdis = b.distanceTo(a);
        let zdir = b.clone().sub(a);

        let path = [
            new Vector2(0, 0),
            new Vector2(-blh, 0),
            new Vector2(-blh, abdis),
            new Vector2(0, abdis)
        ];

        let holePath = new Path()
            .moveTo(-tphd, tphd)
            .lineTo(-blh + tphd, tphd)
            .lineTo(-blh + tphd, abdis - tphd)
            .lineTo(-tphd, abdis - tphd)
            .lineTo(-tphd, tphd);


        let ta = a.clone().add(ydir.clone().negate().setLength(tphd)).add(zdir.clone().setLength(tphd));
        let tb = a.clone().add(ydir.clone().negate().setLength(tphd)).add(zdir.clone().setLength(abdis - tphd));
        let ba = a.clone().add(ydir.clone().negate().setLength(blh - tphd)).add(zdir.clone().setLength(tphd));
        let bb = a.clone().add(ydir.clone().negate().setLength(blh - tphd)).add(zdir.clone().setLength(abdis - tphd));

        let frontface = [ta, ba, bb, tb];

        count = IronUtils.getFaceByFunction(count, vertices, indices, facevec, frontface, path, [holePath],
            (y: number, z: number) => {

                let result = a.clone().add(ydir.clone().setLength(y)).add(zdir.clone().setLength(z));
                return [result.x, result.y, result.z];
            });

        zdir = c.clone().sub(d);
        abdis = c.distanceTo(d);

        path = [
            new Vector2(0, 0),
            new Vector2(-blh, 0),
            new Vector2(-blh, abdis),
            new Vector2(0, abdis)
        ];

        holePath = new Path()
            .moveTo(-tphd, tphd)
            .lineTo(-blh + tphd, tphd)
            .lineTo(-blh + tphd, abdis - tphd)
            .lineTo(-tphd, abdis - tphd)
            .lineTo(-tphd, tphd);

        let td = d.clone().add(ydir.clone().negate().setLength(tphd)).add(zdir.clone().setLength(tphd));
        let tc = d.clone().add(ydir.clone().negate().setLength(tphd)).add(zdir.clone().setLength(abdis - tphd));
        let bd = d.clone().add(ydir.clone().negate().setLength(blh - tphd)).add(zdir.clone().setLength(tphd));
        let bc = d.clone().add(ydir.clone().negate().setLength(blh - tphd)).add(zdir.clone().setLength(abdis - tphd));

        let backface = [td, bd, bc, tc];

        count = IronUtils.getFaceByFunction(count, vertices, indices, facevec, backface, path, [holePath],
            (y: number, z: number) => {

                let result = d.clone().add(ydir.clone().setLength(y)).add(zdir.clone().setLength(z));
                return [result.x, result.y, result.z];
            });

        // 侧面
        let sides = MoldUtils.getSideVIF([...backface, backface[0]], [...frontface, frontface[0]], count);
        vertices.push(...sides[0]);
        indices.push(...sides[1]);
        facevec.push(...sides[2]);
        count = sides[3];

        return count;
    }

    private static addHeadTips(count: number, W: number, H: number, a: Vector3, d: Vector3, normal: Vector3): any[] {
        let tpdis = 10;
        let esdir = d.clone().sub(a).setLength(tpdis);
        let xj = a.clone().add(esdir);

        let xj1 = xj.clone().add(normal.setLength(W * 0.4));
        let xj2 = xj1.clone().add(normal.setLength(W * 0.2));
        let xj3 = xj2.clone().add(esdir.setLength(W * 0.6));
        let xj4 = xj1.clone().add(esdir.setLength(W * 0.4));

        let frontface = [
            new Vector3(xj1.x, H / 2 + 1, xj1.z),
            new Vector3(xj2.x, H / 2 + 1, xj2.z),
            new Vector3(xj3.x, H / 2 + 1, xj3.z),
            new Vector3(xj4.x, H / 2 + 1, xj4.z),
        ]
        let backface = [
            new Vector3(xj1.x, -H / 2 - 1, xj1.z),
            new Vector3(xj2.x, -H / 2 - 1, xj2.z),
            new Vector3(xj3.x, -H / 2 - 1, xj3.z),
            new Vector3(xj4.x, -H / 2 - 1, xj4.z),
        ];

        let vertices = [];
        let indices = [];

        vertices.push(backface[0].x, backface[0].y, backface[0].z);
        vertices.push(backface[1].x, backface[1].y, backface[1].z);
        vertices.push(backface[3].x, backface[3].y, backface[3].z);
        vertices.push(backface[2].x, backface[2].y, backface[2].z);

        indices.push(count, count + 2, count + 1);
        indices.push(count + 2, count + 3, count + 1);

        count += 4;

        vertices.push(frontface[0].x, frontface[0].y, frontface[0].z);
        vertices.push(frontface[1].x, frontface[1].y, frontface[1].z);
        vertices.push(frontface[3].x, frontface[3].y, frontface[3].z);
        vertices.push(frontface[2].x, frontface[2].y, frontface[2].z);

        indices.push(count, count + 1, count + 2);
        indices.push(count + 2, count + 1, count + 3);

        count += 4;

        return [vertices, indices, count]
    }

    /**
     * 水平背楞
     * @param count 
     * @param vertices 
     * @param indices 
     * @param facevec 
     * @param s1 
     * @param e1 
     * @param zhcs 
     * @param W 
     * @param H 
     * @param p_startextend 
     * @param p_endextend 
     * @param p_starttype 
     * @param p_endtype 
     * @param xjdjxg_dis 
     * @param cgdjxg_dis 
     * @param xjgdjxg_dis 
     * @param xjcd 
     * @param xjkd 
     * @param sy 
     * @param blh 
     * @param jxgH 
     * @param tphd 
     * @param kkzj 
     * @param jgW 
     * @param jgH 
     * @param djxgL 
     * @param jxgW 
     * @param data 
     */
    static getHorizontalVI(count: number, vertices: number[], indices: number[], facevec: Vector3[][],
        s1: Vector3, e1: Vector3, typepath: number[][], W: number, H: number,
        p_starttype: number, p_endtype: number, xjdjxg_dis: number, cgdjxg_dis: number, xjgdjxg_dis: number,
        xjcd: number, xjkd: number, jxgH: number, tphd: number, kkzj: string, jgW: number, jgH: number,
        djxgL: number, jxgW: number, p_partdirection: number, data: any) {

        let blh = (H - jxgW) / 2;
        let sy = jxgW / 2;

        let blpaths = DorsalRidgeUtils.getDorsalridgePath(s1, e1, typepath, W, true);

        let sides: any, a: Vector3, b: Vector3, c: Vector3, d: Vector3;
        let esdir: Vector3, sedir: Vector3, tmpdir: Vector3;
        let normal: Vector3;
        // 短矩形间距
        let jianju: number, startjl: number, endjl: number;
        let len: number, middlelen: number;
        let i: number;
        let middlePosAry: number[], middledw: number;
        // 是否是尾端
        let isEnd: boolean = false;

        let frontface: Vector3[], backface: Vector3[];

        let xj1: Vector3, xj2: Vector3, xj3: Vector3;

        data.duan = [];
        data.jgkong = [];
        let st: Vector3, sb: Vector3;
        let jgData: any[];
        let p_startextend = Number(data.p_startextend);
        let p_endextend = Number(data.p_endextend);
        let startDir: Vector3, endDir: Vector3;

        for (let idx = 0; idx < blpaths.length; idx++) {

            a = blpaths[idx][0][0];
            b = blpaths[idx][0][1];
            c = blpaths[idx][0][2];
            d = blpaths[idx][0][3];

            normal = blpaths[idx][1];

            isEnd = false;

            jianju = cgdjxg_dis;

            if (idx === 0) {
                // 处理延申
                startDir = c.clone().sub(b).setLength(p_startextend);
                c.add(startDir);
                d.add(startDir);
            }

            if (idx === blpaths.length - 1) {
                // 处理延申
                endDir = c.clone().sub(b).setLength(p_endextend);
                c.add(endDir);
                d.add(endDir);
            }

            if (idx === 0) {

                if (p_starttype === 1) {
                    // 间距
                    jianju = xjgdjxg_dis;

                    // 斜角
                    if (p_partdirection === 0) {
                        esdir = d.clone().sub(a).setLength(xjcd)
                        xj1 = a.clone().add(esdir);
                        xj2 = b.clone().add(esdir);
                        xj3 = a.clone().add(normal.clone().setLength(W - xjkd));

                        frontface = [
                            new Vector3(xj1.x, H / 2, xj1.z),
                            new Vector3(a.x, H / 2, a.z),
                            new Vector3(xj3.x, H / 2, xj3.z),
                            new Vector3(xj2.x, H / 2, xj2.z),

                            new Vector3(xj1.x, H / 2, xj1.z)
                        ]
                        backface = [
                            new Vector3(xj1.x, -H / 2, xj1.z),
                            new Vector3(a.x, -H / 2, a.z),
                            new Vector3(xj3.x, -H / 2, xj3.z),
                            new Vector3(xj2.x, -H / 2, xj2.z),

                            new Vector3(xj1.x, -H / 2, xj1.z)
                        ];

                        a = xj1.clone();
                        b = xj2.clone();
                    }
                    else {
                        esdir = c.clone().sub(b).setLength(xjcd)
                        xj1 = b.clone().add(esdir);
                        xj2 = a.clone().add(esdir);
                        xj3 = b.clone().sub(normal.clone().setLength(W - xjkd));

                        frontface = [
                            new Vector3(b.x, H / 2, b.z),
                            new Vector3(xj1.x, H / 2, xj1.z),
                            new Vector3(xj2.x, H / 2, xj2.z),
                            new Vector3(xj3.x, H / 2, xj3.z),

                            new Vector3(b.x, H / 2, b.z)
                        ]
                        backface = [
                            new Vector3(b.x, -H / 2, b.z),
                            new Vector3(xj1.x, -H / 2, xj1.z),
                            new Vector3(xj2.x, -H / 2, xj2.z),
                            new Vector3(xj3.x, -H / 2, xj3.z),

                            new Vector3(b.x, -H / 2, b.z)
                        ];

                        a = xj2.clone();
                        b = xj1.clone();
                    }


                    sides = MoldUtils.getVIF(backface, frontface, count);
                    vertices.push(...sides[0]);
                    indices.push(...sides[1]);
                    facevec.push(...sides[2]);
                    count = sides[3];

                }
                else if (p_starttype === 2) {
                    // 角钢
                    jianju = xjdjxg_dis;

                    if (p_partdirection === 0) {

                        st = new Vector3(b.x, H / 2, b.z);
                        sb = new Vector3(b.x, -H / 2, b.z);

                        jgData = DorsalRidgeUtils.getJiaogangVI(count, vertices, indices, facevec, normal.clone(), tphd, kkzj, jgW, jgH,
                            d, a, st, sb);
                        count = jgData[0];
                        data.jgkong.push(0, jgData[1].x, jgData[1].y, jgData[1].z,
                            jgData[2].x, jgData[2].y, jgData[2].z);

                    }
                    else {
                        st = new Vector3(a.x, H / 2, a.z);
                        sb = new Vector3(a.x, -H / 2, a.z);

                        jgData = DorsalRidgeUtils.getJiaogangVI(count, vertices, indices, facevec, normal.clone().negate(), tphd, kkzj, jgW, jgH,
                            c, b, st, sb);
                        count = jgData[0];
                        data.jgkong.push(0, jgData[1].x, jgData[1].y, jgData[1].z,
                            jgData[2].x, jgData[2].y, jgData[2].z);
                    }
                }
                else {
                    jianju = cgdjxg_dis;
                }

                // 头
                let snr = a.clone().sub(b).normalize();
                let ser = c.clone().sub(b).normalize();

                data.bltou = [b.x, 0, b.z, snr.x, snr.y, snr.z, ser.x, ser.y, ser.z, 0, -1, 0];

                let tipsData = DorsalRidgeUtils.addHeadTips(count, W, H, a, d, normal.clone());
                vertices.push(...tipsData[0]);
                indices.push(...tipsData[1]);
                count = tipsData[2];
            }

            if (idx === blpaths.length - 1) {

                if (p_endtype === 1) {
                    // 斜角
                    jianju = xjgdjxg_dis;
                    if (p_partdirection === 0) {
                        sedir = a.clone().sub(d).setLength(xjcd);
                        xj1 = d.clone().add(sedir);
                        xj2 = c.clone().add(sedir);
                        xj3 = d.clone().add(normal.clone().setLength(W - xjkd));

                        frontface = [
                            new Vector3(xj1.x, H / 2, xj1.z),
                            new Vector3(xj2.x, H / 2, xj2.z),
                            new Vector3(xj3.x, H / 2, xj3.z),
                            new Vector3(d.x, H / 2, d.z),

                            new Vector3(xj1.x, H / 2, xj1.z)

                        ]
                        backface = [
                            new Vector3(xj1.x, -H / 2, xj1.z),
                            new Vector3(xj2.x, -H / 2, xj2.z),
                            new Vector3(xj3.x, -H / 2, xj3.z),
                            new Vector3(d.x, -H / 2, d.z),

                            new Vector3(xj1.x, -H / 2, xj1.z)
                        ];

                        d = xj1.clone();
                        c = xj2.clone();
                    }
                    else {
                        sedir = b.clone().sub(c).setLength(xjcd);
                        xj1 = d.clone().add(sedir);
                        xj2 = c.clone().add(sedir);
                        xj3 = c.clone().sub(normal.clone().setLength(W - xjkd));

                        frontface = [
                            new Vector3(xj1.x, H / 2, xj1.z),
                            new Vector3(xj2.x, H / 2, xj2.z),
                            new Vector3(c.x, H / 2, c.z),
                            new Vector3(xj3.x, H / 2, xj3.z),

                            new Vector3(xj1.x, H / 2, xj1.z)
                        ]
                        backface = [
                            new Vector3(xj1.x, -H / 2, xj1.z),
                            new Vector3(xj2.x, -H / 2, xj2.z),
                            new Vector3(c.x, -H / 2, c.z),
                            new Vector3(xj3.x, -H / 2, xj3.z),

                            new Vector3(xj1.x, -H / 2, xj1.z)
                        ];

                        d = xj1.clone();
                        c = xj2.clone();
                    }
                    sides = MoldUtils.getVIF(backface, frontface, count);
                    vertices.push(...sides[0]);
                    indices.push(...sides[1]);
                    facevec.push(...sides[2]);
                    count = sides[3];
                }
                else if (p_endtype === 2) {
                    // 角钢
                    jianju = xjdjxg_dis;

                    if (p_partdirection === 0) {
                        st = new Vector3(c.x, H / 2, c.z);
                        sb = new Vector3(c.x, -H / 2, c.z);

                        jgData = DorsalRidgeUtils.getJiaogangVI(count, vertices, indices, facevec, normal.clone(), tphd, kkzj, jgW, jgH,
                            a, d, st, sb);

                        count = jgData[0];
                        data.jgkong.push(1, jgData[1].x, jgData[1].y, jgData[1].z,
                            jgData[2].x, jgData[2].y, jgData[2].z);

                    }
                    else {
                        st = new Vector3(d.x, H / 2, d.z);
                        sb = new Vector3(d.x, -H / 2, d.z);

                        jgData = DorsalRidgeUtils.getJiaogangVI(count, vertices, indices, facevec, normal.clone().negate(), tphd, kkzj, jgW, jgH,
                            b, c, st, sb);

                        count = jgData[0];
                        data.jgkong.push(1, jgData[1].x, jgData[1].y, jgData[1].z,
                            jgData[2].x, jgData[2].y, jgData[2].z);
                    }

                }
                else {
                    jianju = cgdjxg_dis;
                }
                isEnd = blpaths.length === 1 ? false : true;

                // 尾
                let ner = d.clone().sub(c).normalize();
                let eer = b.clone().sub(c).normalize();
                data.blwei = [c.x, 0, c.z, ner.x, ner.y, ner.z, eer.x, eer.y, eer.z, 0, -1, 0];
            }

            data.duan.push(
                a.x, sy + blh, a.z,
                b.x, sy + blh, b.z,
                c.x, sy + blh, c.z,
                d.x, sy + blh, d.z,

                a.x, -sy - blh, a.z,
                b.x, -sy - blh, b.z,
                c.x, -sy - blh, c.z,
                d.x, -sy - blh, d.z
            )

            // 上背楞
            frontface = [
                new Vector3(a.x, sy, a.z),
                new Vector3(b.x, sy, b.z),
                new Vector3(b.x, sy + blh, b.z),
                new Vector3(a.x, sy + blh, a.z)
            ]

            backface = [
                new Vector3(d.x, sy, d.z),
                new Vector3(c.x, sy, c.z),
                new Vector3(c.x, sy + blh, c.z),
                new Vector3(d.x, sy + blh, d.z)
            ]

            // 侧面
            sides = MoldUtils.getSideVIF([...backface, backface[0]], [...frontface, frontface[0]], count);
            vertices.push(...sides[0]);
            indices.push(...sides[1]);
            facevec.push(...sides[2]);
            count = sides[3];

            count = DorsalRidgeUtils.getHolePathVI(count, vertices, indices, facevec, blh, tphd,
                new Vector3(a.x, sy + blh, a.z),
                new Vector3(b.x, sy + blh, b.z),
                new Vector3(c.x, sy + blh, c.z),
                new Vector3(d.x, sy + blh, d.z),
                new Vector3(0, 1, 0)
            );

            // 下背楞
            frontface = [
                new Vector3(a.x, -sy, a.z),
                new Vector3(b.x, -sy, b.z),
                new Vector3(b.x, -sy - blh, b.z),
                new Vector3(a.x, -sy - blh, a.z)
            ]

            backface = [
                new Vector3(d.x, -sy, d.z),
                new Vector3(c.x, -sy, c.z),
                new Vector3(c.x, -sy - blh, c.z),
                new Vector3(d.x, -sy - blh, d.z)
            ]

            // 侧面
            sides = MoldUtils.getSideVIF([...backface, backface[0]], [...frontface, frontface[0]], count);
            vertices.push(...sides[0]);
            indices.push(...sides[1]);
            facevec.push(...sides[2]);
            count = sides[3];

            count = DorsalRidgeUtils.getHolePathVI(count, vertices, indices, facevec, blh, tphd,
                new Vector3(a.x, -sy, a.z),
                new Vector3(b.x, -sy, b.z),
                new Vector3(c.x, -sy, c.z),
                new Vector3(d.x, -sy, d.z),
                new Vector3(0, 1, 0)
            );

            let len = d.distanceTo(a);
            if (blpaths.length === 1) {

                startjl = jianju;
                endjl = len - jianju - jxgH;
                // 算中间
                middlelen = len - jianju * 2;

                // 位置集合
                middlePosAry = isEnd ? [endjl, startjl] : [startjl, endjl];
            }
            else {
                if (idx === 0 || idx === blpaths.length - 1) {

                    startjl = jianju;
                    // 算中间
                    middlelen = len - jianju;

                    // 位置集合
                    middlePosAry = isEnd ? [middlelen] : [startjl];
                }
                else {
                    continue;
                }
            }


            // 背楞中间的短矩形
            let middlebz = AModelFmulaUtils.getHolesbyExpress(data['C' + AK.djxgbz], middlelen, 2);
            if (middlebz && middlebz.length > 0) {
                for (i = 0; i < middlebz.length; i++) {
                    middledw = isEnd ? len - startjl - middlebz[i] : startjl + middlebz[i];
                    middlePosAry.push(middledw);
                }
            }

            let sd = (W - djxgL) / 2;
            let ed = djxgL;
            tmpdir = d.clone().sub(a);
            let tmppos1: Vector3, tmppos2: Vector3, tmppos3: Vector3, tmppos4: Vector3;
            for (i = 0; i < middlePosAry.length; i++) {
                tmppos1 = a.clone().add(normal.clone().setLength(sd)).add(tmpdir.setLength(middlePosAry[i]));
                tmppos2 = tmppos1.clone().add(tmpdir.setLength(jxgH));
                tmppos3 = tmppos2.clone().add(normal.clone().setLength(ed));
                tmppos4 = tmppos1.clone().add(normal.clone().setLength(ed));

                frontface = [
                    new Vector3(tmppos1.x, jxgW / 2, tmppos1.z),
                    new Vector3(tmppos2.x, jxgW / 2, tmppos2.z),
                    new Vector3(tmppos3.x, jxgW / 2, tmppos3.z),
                    new Vector3(tmppos4.x, jxgW / 2, tmppos4.z),
                    new Vector3(tmppos1.x, jxgW / 2, tmppos1.z)
                ]
                backface = [
                    new Vector3(tmppos1.x, -jxgW / 2, tmppos1.z),
                    new Vector3(tmppos2.x, -jxgW / 2, tmppos2.z),
                    new Vector3(tmppos3.x, -jxgW / 2, tmppos3.z),
                    new Vector3(tmppos4.x, -jxgW / 2, tmppos4.z),
                    new Vector3(tmppos1.x, -jxgW / 2, tmppos1.z)
                ]
                sides = MoldUtils.getSideVIF(backface, frontface, count);
                vertices.push(...sides[0]);
                indices.push(...sides[1]);
                facevec.push(...sides[2]);
                count = sides[3];
            }


        }

    }

    /**
     * 竖直多边背楞路径
     * @param path 
     * @param L 
     * @param arc 
     * @param W 
     * @param normal 
     * @param even 
     * @returns 
     */
    static getVIronPath(path: Vector3[], L: number, arc: number, W: number, normal: Vector3, even: boolean) {

        let s: Vector3, e: Vector3, sp: Vector3, ep: Vector3;
        let ns: Vector3, ne: Vector3, nsp: Vector3, nep: Vector3;

        s = path[0];
        sp = path[1];
        ep = path[2];
        e = path[3];

        let se = e.clone().sub(s);
        let dir: Vector3 = se.clone().normalize();
        let senor: Vector3 = sp.clone().sub(s).normalize();

        let nor: Vector3;
        let angle: number;

        if (even) {

            dir.applyAxisAngle(normal, arc);
            dir.setLength(L);

            angle = senor.clone().angleTo(dir);

            if (angle < Math.PI / 2) {
                ns = ep.clone();
                ne = ep.clone().add(dir);
            }
            else {
                ns = e.clone();
                ne = e.clone().add(dir);
            }

            if (arc < 0) {
                nor = dir.clone().applyAxisAngle(normal, -Math.PI / 2);
                nor.setLength(W);
            }
            else {
                nor = dir.clone().applyAxisAngle(normal, Math.PI / 2);
                nor.setLength(W);
            }

            nsp = ns.clone().add(nor);
            nep = ne.clone().add(nor);
        }
        else {

            dir.applyAxisAngle(normal, arc);
            dir.setLength(L);

            angle = senor.clone().angleTo(dir);

            if (angle > Math.PI / 2) {
                ns = ep.clone();
                ne = ep.clone().add(dir);
            }
            else {
                ns = e.clone();
                ne = e.clone().add(dir);
            }

            if (arc < 0) {
                nor = dir.clone().applyAxisAngle(normal, Math.PI / 2);
                nor.setLength(W);
            }
            else {
                nor = dir.clone().applyAxisAngle(normal, -Math.PI / 2);
                nor.setLength(W);
            }

            nsp = ns.clone().add(nor);
            nep = ne.clone().add(nor);

        }
        return [ns, nsp, nep, ne, ns];

    }

    static getVIronPaths(s1: Vector3, e1: Vector3, typepath: any[], H: number, jxgW: number): Vector3[][] {
        let dir: Vector3, normal: Vector3, bnor: Vector3, tnor: Vector3;

        let length: number, angle: number, type: number, th: number;

        let st: Vector3, et: Vector3, sb: Vector3, eb: Vector3;

        let up = new Vector3(0, 1, 0);

        let allPath: Vector3[][] = [];
        // 求第一个
        type = typepath[0][2];
        th = type === 2 ? (H - jxgW) / 2 : H;

        dir = e1.clone().sub(s1);

        normal = dir.clone().cross(up).normalize();

        bnor = dir.clone().applyAxisAngle(normal, -Math.PI / 2);
        tnor = bnor.clone().negate();

        bnor.setLength(th / 2);
        tnor.setLength(th / 2);

        st = s1.clone().add(tnor);
        et = e1.clone().add(tnor);
        sb = s1.clone().add(bnor);
        eb = e1.clone().add(bnor);

        let path: Vector3[] = [st, sb, eb, et, st];

        allPath.push(path);

        for (let i = 1; i < typepath.length; i++) {
            length = typepath[i][0];
            angle = typepath[i][1];
            type = typepath[i][2];

            // 管厚度
            th = type === 2 ? (H - jxgW) / 2 : H;

            path = DorsalRidgeUtils.getVIronPath(allPath[allPath.length - 1], length, angle / 180 * Math.PI, th, normal, i % 2 === 0);

            allPath.push(path);
        }
        return allPath;
    }


    static getJiaogangVI(count: number, vertices: any[], indices: any[], facevec: any[],
        normal: Vector3, tphd: number, kkzj: string, jgW: number, jgH: number,
        d: Vector3, a: Vector3, af: Vector3, bf: Vector3): any[] {

        let jgL: number = MoldUtils.SqrtValue(jgH, jgW);
        let cosA = jgW / jgL;
        let sinA = jgH / jgL;


        let ox = jgW * cosA;
        let oy = jgW * sinA;

        let addir = d.clone().sub(a);

        let wl = tphd / sinA;
        let hl = tphd / cosA;
        // 左内点
        let zptn = af.clone().add(addir.setLength(wl));
        let zpbn = bf.clone().add(addir.setLength(wl));

        // 右外点
        let yptw = af.clone().add(addir.setLength(jgL));
        let ypbw = bf.clone().add(addir.setLength(jgL));

        // 右内点
        let yptn = af.clone().add(addir.setLength(jgL - hl));
        let ypbn = bf.clone().add(addir.setLength(jgL - hl));

        // 中间外点
        let mptw = af.clone().add(addir.setLength(ox)).add(normal.clone().setLength(oy));
        let mpbw = bf.clone().add(addir.setLength(ox)).add(normal.clone().setLength(oy));

        let lcenter = mptw.clone().add(yptw).multiplyScalar(0.5);
        lcenter.add(mpbw.clone().sub(mptw).setLength(af.distanceTo(bf) / 2));

        // 
        let madir = af.clone().sub(mptw);
        let mddir = yptw.clone().sub(mptw);

        // 中间内点
        let mptn = mptw.clone().add(madir.setLength(tphd)).add(mddir.setLength(tphd));
        let mpbn = mpbw.clone().add(madir.setLength(tphd)).add(mddir.setLength(tphd));

        // 宽板
        let frontface = [af, bf, zpbn, zptn, af];
        let backface = [mptw, mpbw, mpbn, mptn, mptw];

        let sides = MoldUtils.getSideVIF(backface, frontface, count);
        vertices.push(...sides[0]);
        indices.push(...sides[1]);
        facevec.push(...sides[2]);
        count = sides[3];

        // 高板
        let holePath: Path;
        let bholePath: Path;
        let kongAry = kkzj.split('*');

        if (kongAry.length === 2) {
            let rw = Number(kongAry[0]);
            let rl = Number(kongAry[1]);

            let dis = mptn.distanceTo(yptn);

            holePath = new Path()
                .moveTo(rw / 2, 0)
                .lineTo(rw / 2, rl - rw / 2)
                .absarc(0, rl - rw / 2, rw / 2, 0, Math.PI, false)
                .lineTo(-rw / 2, rl - rw / 2)
                .lineTo(-rw / 2, 0)

            bholePath = new Path()
                .moveTo(rw / 2, 0)
                .lineTo(rw / 2, dis - rw / 2)
                .absarc(0, dis - rw / 2, rw / 2, 0, Math.PI, false)
                .lineTo(-rw / 2, dis - rw / 2)
                .lineTo(-rw / 2, 0)
        }

        let hdis = af.distanceTo(bf);
        let path = [
            new Vector2(-hdis / 2, 0),
            new Vector2(hdis / 2, 0),
            new Vector2(hdis / 2, jgH),
            new Vector2(-hdis / 2, jgH)
        ];

        let bdis = mptn.distanceTo(yptn);
        let bpath = [
            new Vector2(-hdis / 2, 0),
            new Vector2(hdis / 2, 0),
            new Vector2(hdis / 2, bdis),
            new Vector2(-hdis / 2, bdis)
        ];

        frontface = [mptw, mpbw, ypbw, yptw];
        frontface = [mptn, mpbn, ypbn, yptn];

        let mtargetw = yptw.clone().add(ypbw).multiplyScalar(0.5);
        let mtargetn = yptn.clone().add(ypbn).multiplyScalar(0.5);

        let ydir = af.clone().sub(bf);

        let zdir = mptw.clone().sub(yptw);

        count = IronUtils.getFaceByFunction(count, vertices, indices, facevec, frontface, path, [holePath],
            (a: number, b: number) => {

                let result = mtargetw.clone().add(ydir.clone().setLength(a)).add(zdir.clone().setLength(b));
                return [result.x, result.y, result.z];
            });
        count = IronUtils.getFaceByFunction(count, vertices, indices, facevec, frontface, bpath, [bholePath],
            (a: number, b: number) => {

                let result = mtargetn.clone().add(ydir.clone().setLength(a)).add(zdir.clone().setLength(b));
                return [result.x, result.y, result.z];
            });


        // 顶
        frontface = [mptn, mptw, yptw, yptn];
        count = IronUtils.addVectorFaceVI(count, vertices, indices, facevec, frontface);

        // 底
        backface = [mpbn, mpbw, ypbw, ypbn];
        count = IronUtils.addVectorFaceVI(count, vertices, indices, facevec, backface);

        return [count, lcenter, af.clone().sub(mptw)];
    }

    /**
     * 垂直背楞
     * @param count 
     * @param vertices 
     * @param indices 
     * @param facevec 
     * @param s1 
     * @param e1 
     * @param typepath 
     * @param W 
     * @param H 
     * @param p_starttype 
     * @param p_endtype 
     * @param xjdjxg_dis 
     * @param cgdjxg_dis 
     * @param xjgdjxg_dis 
     * @param xjcd 
     * @param xjkd 
     * @param jxgH 
     * @param tphd 
     * @param kkzj 
     * @param jgW 
     * @param jgH 
     * @param djxgL 
     * @param jxgW 
     * @param data 
     */
    static getVerticalVI(count: number, vertices: number[], indices: number[], facevec: Vector3[][],
        s1: Vector3, e1: Vector3, typepath: number[][], W: number, H: number, p_starttype: number, p_endtype: number,
        xjdjxg_dis: number, cgdjxg_dis: number, xjgdjxg_dis: number, xjcd: number, xjkd: number, jxgH: number,
        tphd: number, kkzj: string, jgW: number, jgH: number, djxgL: number, jxgW: number, p_partdirection: number, data: ALParams) {

        let up = new Vector3(0, 1, 0);

        let se = e1.clone().sub(s1);

        let normal = se.clone().cross(up).setLength(W);

        let paths = DorsalRidgeUtils.getVIronPaths(s1, e1, typepath, H, jxgW);

        data.duan = [];
        data.jgkong = [];
        // for (let i = 0; i < paths.length; i++) {
        //     for (let j = 0; j < paths[i].length - 1; j++) {
        //         data.duan.push(paths[i][j].x, paths[i][j].y, paths[i][j].z)
        //     }
        // }

        let a: Vector3, b: Vector3, c: Vector3, d: Vector3;

        let ab: Vector3, bb: Vector3, cb: Vector3, db: Vector3;

        let af: Vector3, bf: Vector3, cf: Vector3, df: Vector3;

        let abt: Vector3, bbt: Vector3, cbt: Vector3, dbt: Vector3;

        let aft: Vector3, bft: Vector3, cft: Vector3, dft: Vector3;

        // 短矩形
        let azjx: Vector3, bzjx: Vector3, czjx: Vector3, dzjx: Vector3;
        let ayjx: Vector3, byjx: Vector3, cyjx: Vector3, dyjx: Vector3;

        let azjxp: Vector3, bzjxp: Vector3, byjxp: Vector3, ayjxp: Vector3;
        let azjxh: Vector3, bzjxh: Vector3, byjxh: Vector3, ayjxh: Vector3;

        let esdir: Vector3, sedir: Vector3, tmpdir: Vector3;

        let xj1: Vector3, xj2: Vector3, xj3: Vector3, xj4: Vector3, xj5: Vector3, xj6: Vector3;

        let frontface: Vector3[], backface: Vector3[];

        let type: number, i: number;

        let middlePosAry: number[], middledw: number;
        // 是否是尾端
        let isEnd: boolean = false;

        let sides: any[];
        let jgData: any[];
        let jianju: number, startjl: number, endjl: number, middlelen: number;

        let p_startextend = Number(data.p_startextend);
        let p_endextend = Number(data.p_endextend);
        let startDir: Vector3, endDir: Vector3;

        for (let idx = 0; idx < paths.length; idx++) {
            a = paths[idx][0];
            b = paths[idx][1];
            c = paths[idx][2];
            d = paths[idx][3];

            // 2 单管 1 双管
            type = typepath[idx][2];

            // 短矩形间距
            jianju = cgdjxg_dis;

            isEnd = false;

            if (idx === 0) {
                // 处理延申
                startDir = d.clone().sub(a).setLength(p_startextend);
                c.add(startDir);
                d.add(startDir);

            }

            if (idx === paths.length - 1) {
                // 处理延申
                endDir = d.clone().sub(a).setLength(p_endextend);
                c.add(endDir);
                d.add(endDir);
            }


            // 轮廓点
            ab = a.clone();
            bb = b.clone();
            cb = c.clone();
            db = d.clone();

            af = a.clone().add(normal);
            bf = b.clone().add(normal);
            cf = c.clone().add(normal);
            df = d.clone().add(normal);


            // 头
            if (idx === 0) {



                if (p_starttype === 1) {

                    jianju = xjgdjxg_dis;
                    // 斜角
                    esdir = d.clone().sub(a).setLength(xjcd);

                    if (p_partdirection === 0) {
                        xj1 = ab.clone().add(esdir);
                        xj2 = bb.clone().add(esdir);
                        xj3 = af.clone().add(esdir);
                        xj4 = bf.clone().add(esdir);
                        xj5 = ab.clone().add(normal.clone().setLength(W - xjkd));
                        xj6 = bb.clone().add(normal.clone().setLength(W - xjkd));

                        frontface = [xj1, xj3, xj5, ab.clone(), xj1];
                        backface = [xj2, xj4, xj6, bb.clone(), xj2];

                        ab = xj1.clone();
                        bb = xj2.clone();
                        af = xj3.clone();
                        bf = xj4.clone();
                    }
                    else {

                        xj1 = ab.clone().add(esdir);
                        xj2 = bb.clone().add(esdir);
                        xj3 = af.clone().add(esdir);
                        xj4 = bf.clone().add(esdir);
                        xj5 = af.clone().sub(normal.clone().setLength(W - xjkd));
                        xj6 = bf.clone().sub(normal.clone().setLength(W - xjkd));


                        frontface = [xj1, xj3, af.clone(), xj5, xj1];
                        backface = [xj2, xj4, bf.clone(), xj6, xj2];

                        ab = xj1.clone();
                        bb = xj2.clone();
                        af = xj3.clone();
                        bf = xj4.clone();
                    }

                    sides = MoldUtils.getVIF(backface, frontface, count);
                    vertices.push(...sides[0]);
                    indices.push(...sides[1]);
                    facevec.push(...sides[2]);
                    count = sides[3];

                }
                else if (p_starttype === 2) {

                    jianju = xjdjxg_dis;

                    // 角钢
                    // 角钢长度
                    if (p_partdirection === 0) {
                        jgData = DorsalRidgeUtils.getJiaogangVI(count, vertices, indices, facevec, normal.clone(), tphd, kkzj, jgW, jgH,
                            d, a, af, bf);
                        count = jgData[0];
                        data.jgkong.push(0, jgData[1].x, jgData[1].y, jgData[1].z,
                            jgData[2].x, jgData[2].y, jgData[2].z);
                    }
                    else {
                        jgData = DorsalRidgeUtils.getJiaogangVI(count, vertices, indices, facevec, normal.clone().negate(), tphd, kkzj, jgW, jgH,
                            d, a, ab, bb);
                        count = jgData[0];
                        data.jgkong.push(0,
                            jgData[1].x, jgData[1].y, jgData[1].z,
                            jgData[2].x, jgData[2].y, jgData[2].z);
                    }

                }
                else {
                    jianju = cgdjxg_dis;
                }

                let tounor = ab.clone().sub(af).normalize();
                let toudir = cf.clone().sub(af).normalize();
                let touDown = bf.clone().sub(af).normalize();
                let tou = af.clone().add(bf).multiplyScalar(0.5);
                data.bltou = [tou.x, tou.y, tou.z, tounor.x, tounor.y, tounor.z, toudir.x, toudir.y, toudir.z, touDown.x, touDown.y, touDown.z];

                let tipsData = DorsalRidgeUtils.addHeadTips(count, W, H, ab, db, normal.clone());
                vertices.push(...tipsData[0]);
                indices.push(...tipsData[1]);
                count = tipsData[2];
            }

            // 尾
            if (idx === paths.length - 1) {


                if (p_endtype === 1) {
                    // 斜角
                    jianju = xjgdjxg_dis;

                    sedir = a.clone().sub(d).setLength(xjcd);
                    if (p_partdirection === 0) {
                        xj1 = db.clone().add(sedir);
                        xj2 = cb.clone().add(sedir);
                        xj3 = df.clone().add(sedir);
                        xj4 = cf.clone().add(sedir);

                        xj5 = db.clone().add(normal.clone().setLength(W - xjkd));
                        xj6 = cb.clone().add(normal.clone().setLength(W - xjkd));

                        frontface = [xj1, xj3, xj5, db.clone(), xj1];
                        backface = [xj2, xj4, xj6, cb.clone(), xj2];

                        db = xj1.clone();
                        cb = xj2.clone();
                        df = xj3.clone();
                        cf = xj4.clone();
                    }
                    else {

                        xj1 = db.clone().add(sedir);
                        xj2 = cb.clone().add(sedir);
                        xj3 = df.clone().add(sedir);
                        xj4 = cf.clone().add(sedir);

                        xj5 = df.clone().sub(normal.clone().setLength(W - xjkd));
                        xj6 = cf.clone().sub(normal.clone().setLength(W - xjkd));

                        frontface = [xj1, xj3, df.clone(), xj5, xj1];
                        backface = [xj2, xj4, cf.clone(), xj6, xj2];

                        db = xj1.clone();
                        cb = xj2.clone();
                        df = xj3.clone();
                        cf = xj4.clone();
                    }

                    let weinor = db.clone().sub(df).normalize();
                    let weidir = af.clone().sub(df).normalize();
                    let weiDown = cf.clone().sub(df).normalize();
                    let wei = df.clone().add(cf).multiplyScalar(0.5);
                    data.blwei = [wei.x, wei.y, wei.z, weinor.x, weinor.y, weinor.z, weidir.x, weidir.y, weidir.z, weiDown.x, weiDown.y, weiDown.z];

                    sides = MoldUtils.getVIF(backface, frontface, count);
                    vertices.push(...sides[0]);
                    indices.push(...sides[1]);
                    facevec.push(...sides[2]);
                    count = sides[3];

                }
                else if (p_endtype === 2) {
                    // 角钢
                    jianju = xjdjxg_dis;
                    if (p_partdirection === 0) {
                        jgData = DorsalRidgeUtils.getJiaogangVI(count, vertices, indices, facevec, normal.clone(), tphd, kkzj, jgW, jgH,
                            a, d, df, cf);
                        count = jgData[0];
                        data.jgkong.push(1, jgData[1].x, jgData[1].y, jgData[1].z,
                            jgData[2].x, jgData[2].y, jgData[2].z);

                    }
                    else {
                        jgData = DorsalRidgeUtils.getJiaogangVI(count, vertices, indices, facevec, normal.clone().negate(), tphd, kkzj, jgW, jgH,
                            a, d, db, cb);
                        count = jgData[0];
                        data.jgkong.push(1, jgData[1].x, jgData[1].y, jgData[1].z,
                            jgData[2].x, jgData[2].y, jgData[2].z);
                    }

                }
                else {
                    jianju = cgdjxg_dis;
                }

                isEnd = paths.length === 1 ? false : true;
            }


            if (type === 2) {


                frontface = [ab, bb, bf, af];

                backface = [db, cb, cf, df];

                // 侧面
                sides = MoldUtils.getSideVIF([...backface, backface[0]], [...frontface, frontface[0]], count);
                vertices.push(...sides[0]);
                indices.push(...sides[1]);
                facevec.push(...sides[2]);
                count = sides[3];

                count = DorsalRidgeUtils.getHolePathVI(count, vertices, indices, facevec, (H - jxgW) / 2, tphd,
                    ab, af, df, db, ab.clone().sub(bb)
                );

            }
            else {
                let badir = b.clone().sub(a);
                let abdir = a.clone().sub(b);

                let th = (H - jxgW) / 2;
                abt = ab.clone().add(badir.setLength(th));
                aft = af.clone().add(badir.setLength(th));
                dbt = db.clone().add(badir.setLength(th));
                dft = df.clone().add(badir.setLength(th));

                bbt = bb.clone().add(abdir.setLength(th));
                bft = bf.clone().add(abdir.setLength(th));
                cbt = cb.clone().add(abdir.setLength(th));
                cft = cf.clone().add(abdir.setLength(th));

                frontface = [ab, abt, aft, af];
                backface = [db, dbt, dft, df];

                // 侧面
                sides = MoldUtils.getSideVIF([...backface, backface[0]], [...frontface, frontface[0]], count);
                vertices.push(...sides[0]);
                indices.push(...sides[1]);
                facevec.push(...sides[2]);
                count = sides[3];

                count = DorsalRidgeUtils.getHolePathVI(count, vertices, indices, facevec, th, tphd,
                    ab, af, df, db, ab.clone().sub(bb)
                );

                frontface = [bbt, bb, bf, bft];
                backface = [cbt, cb, cf, cft];

                // 侧面
                sides = MoldUtils.getSideVIF([...backface, backface[0]], [...frontface, frontface[0]], count);
                vertices.push(...sides[0]);
                indices.push(...sides[1]);
                facevec.push(...sides[2]);
                count = sides[3];

                count = DorsalRidgeUtils.getHolePathVI(count, vertices, indices, facevec, th, tphd,
                    bbt, bft, cft, cbt, bbt.clone().sub(bb)
                );

                // 短矩形
                let len = d.distanceTo(a);
                if (paths.length === 1) {

                    startjl = jianju;
                    endjl = len - jianju - jxgH;
                    // 算中间
                    middlelen = len - jianju * 2;

                    // 位置集合
                    middlePosAry = isEnd ? [endjl, startjl] : [startjl, endjl];
                }
                else {
                    if (idx === 0 || idx === paths.length - 1) {

                        startjl = jianju;
                        // 算中间
                        middlelen = len - jianju;

                        // 位置集合
                        middlePosAry = isEnd ? [middlelen] : [startjl];
                    }
                    else {
                        continue;
                    }
                }

                // 背楞中间的短矩形
                let middlebz = AModelFmulaUtils.getHolesbyExpress(data['C' + AK.djxgbz], middlelen, 2, data, 'C' + AK.djxgbz);
                if (middlebz && middlebz.length > 0) {
                    for (i = 0; i < middlebz.length; i++) {
                        middledw = isEnd ? len - startjl - middlebz[i] : startjl + middlebz[i];
                        middlePosAry.push(middledw);
                    }
                }

                // 求短矩形得轮廓点
                let dpdir = b.clone().sub(a);
                let tpdir = a.clone().sub(b);

                azjx = a.clone().add(normal.clone().setLength((W - djxgL) / 2)).add(dpdir.setLength(th));
                ayjx = a.clone().add(normal.clone().setLength((W + djxgL) / 2)).add(dpdir.setLength(th));

                bzjx = b.clone().add(normal.clone().setLength((W - djxgL) / 2)).add(tpdir.setLength(th));
                byjx = b.clone().add(normal.clone().setLength((W + djxgL) / 2)).add(tpdir.setLength(th));

                let djxdir = d.clone().sub(a);

                for (i = 0; i < middlePosAry.length; i++) {

                    bzjxp = bzjx.clone().add(djxdir.clone().setLength(middlePosAry[i]));
                    byjxp = byjx.clone().add(djxdir.clone().setLength(middlePosAry[i]));
                    ayjxp = ayjx.clone().add(djxdir.clone().setLength(middlePosAry[i]));
                    azjxp = azjx.clone().add(djxdir.clone().setLength(middlePosAry[i]));

                    bzjxh = bzjx.clone().add(djxdir.clone().setLength(middlePosAry[i] + jxgH));
                    byjxh = byjx.clone().add(djxdir.clone().setLength(middlePosAry[i] + jxgH));
                    ayjxh = ayjx.clone().add(djxdir.clone().setLength(middlePosAry[i] + jxgH));
                    azjxh = azjx.clone().add(djxdir.clone().setLength(middlePosAry[i] + jxgH));

                    frontface = [bzjxp, byjxp, byjxh, bzjxh, bzjxp];
                    backface = [azjxp, ayjxp, ayjxh, azjxh, azjxp];

                    sides = MoldUtils.getSideVIF(backface, frontface, count);
                    vertices.push(...sides[0]);
                    indices.push(...sides[1]);
                    facevec.push(...sides[2]);
                    count = sides[3];
                }
            }

            data.duan.push(
                ab.x, ab.y, ab.z,
                bb.x, bb.y, bb.z,
                cb.x, cb.y, cb.z,
                db.x, db.y, db.z,
                af.x, af.y, af.z,
                bf.x, bf.y, bf.z,
                cf.x, cf.y, cf.z,
                df.x, df.y, df.z
            )

        }

    }
    static checkDRVertical(path: any[], err: number = 0.1): boolean {
        for (let i = 1; i < path.length; i++) {
            if (Math.abs(Math.abs(path[i][1]) - 90) > err) {
                return false;
            }
        }
        return true;
    }
    /**
    * 背楞
    * @param data 
    * @returns 
    */
    static getDorsalRidgeVI(data: ALParams): any[] {

        // 计数
        let count: number = 0;
        // 数据
        let vertices: any[] = [];
        let indices: any[] = [];
        let facevec: any[] = [];

        // 长宽高
        let L: number = Number(data.L);
        let W: number = Number(data.W);
        let H: number = Number(data.H);

        // 铁皮厚度
        let tphd = Number(data.tphd);
        // 开孔直径
        let kkzj = data.kkzj;

        // 角钢宽
        let jgW = Number(data.jgW);
        // 角钢高
        let jgH = Number(data.jgH);

        // 短矩形管高
        let jxgH = Number(data.jxgH);
        // 短矩形管宽
        let jxgW = Number(data.jxgW);
        // 短矩形管长
        let djxgL = Number(data.djxgL);

        // 常规端矩形管边距
        let cgdjxg_dis = Number(data.cgdjxg_dis);
        // 斜角钢端矩形管边距
        let xjgdjxg_dis = Number(data.xjgdjxg_dis);
        // 斜角端矩形管边距
        let xjdjxg_dis = Number(data.xjdjxg_dis);

        // 斜角长度
        let xjcd = Number(data.xjcd);
        // 斜角宽度
        let xjkd = Number(data.xjkd);

        // /** 斜角端部伸出长度 */
        // let xjdbL = Number(data.xjdbL);
        // /** 斜角钢端部伸出长度 */
        // let xjgdbL = Number(data.xjgdbL);

        // 延申
        let p_startextend = Number(data.p_startextend);
        let p_endextend = Number(data.p_endextend);

        // 长度及角度
        if (data.zhcs === "") {
            data.zhcs = '(' + L + ',' + 0 + ',' + 0 + ')';
        }

        if (!data.p_sepoint || data.p_sepoint.length != 3) {
            if (isNaN(L)) {

            }
            else {
                data.p_sepoint = [L, 0, 0];
            }
        }

        // K板调节：起始/结束端默认'常规生产'
        if (data.p_kplateadjust === 1) {
            data.p_starttype = 0;
            data.p_endtype = 0;
        }


        let p_starttype = data.p_starttype;
        let p_endtype = data.p_endtype;
        let p_partdirection = data.p_partdirection;


        // 检测类型
        let typepath = DorsalRidgeUtils.getLenagData(data.zhcs);

        // 过滤掉非法输入
        let str: string = '';
        for (let i = 0; i < typepath.length; i++) {
            str += '(' + typepath[i][0] + ',' + typepath[i][1] + ',' + typepath[i][2] + ')'
        }
        data.zhcs = str;

        // 
        if (!data.p_sepoint || data.p_sepoint.length != 3) {
            data.p_sepoint = [typepath[0][0], 0, 0];
        }

        let p_sepoint = data.p_sepoint;
        // 起始端点
        let s1 = new Vector3(0, 0, 0);
        let e1 = new Vector3(p_sepoint[0], p_sepoint[1], p_sepoint[2]);

        // 第一段长
        let lenth = typepath[0][0];

        let sedis = s1.distanceTo(e1);
        if (Math.abs(sedis - lenth) > 0.5) {
            // 认为两个不相等
            let sedir = e1.clone().sub(s1);
            sedir.setLength(lenth);
            e1 = sedir;
        }

        let type = typepath[0][2];
        if (type != 0) {
            // 单管
            DorsalRidgeUtils.getVerticalVI(count, vertices, indices, facevec, s1, e1, typepath, W, H,
                p_starttype, p_endtype, xjdjxg_dis, cgdjxg_dis, xjgdjxg_dis, xjcd, xjkd, jxgH, tphd,
                kkzj, jgW, jgH, djxgL, jxgW, p_partdirection, data);
        }
        else {
            // 默认水平
            DorsalRidgeUtils.getHorizontalVI(count, vertices, indices, facevec, s1, e1, typepath, W, H,
                p_starttype, p_endtype, xjdjxg_dis, cgdjxg_dis, xjgdjxg_dis, xjcd, xjkd, jxgH, tphd,
                kkzj, jgW, jgH, djxgL, jxgW, p_partdirection, data);
        }

        str = '';
        for (let i = 0; i < typepath.length; i++) {
            if (i === 0) {
                typepath[i][0] += p_startextend;
                // if (p_starttype === 1) {
                //     typepath[i][0] += xjcd;
                // }
            }
            if (i === typepath.length - 1) {
                typepath[i][0] += p_endextend;
                // if (p_endtype === 1) {
                //     typepath[i][0] += xjcd;
                // }
            }

            str += '(' + typepath[i][0] + ',' + typepath[i][1] + ',' + typepath[i][2] + ')'
        }
        data.zhcs = str;

        return [vertices, indices, facevec];
    }

}